<?php

namespace App\Models;

class GoodsPicPrimaryModel extends ToyModel
{
    protected $table = 'pic_primary';

    /**
     * 获取模型
     * @param $request
     * @return mixed
     */
    public static function getModel($request): mixed
    {
        $Model = self::where('PStatus', 0)->where('PID', 0);
        return self::getQueryModel($Model, $request);
    }

    /**
     * 合并视图和主图模型的查询
     * @param $model
     * @param $request
     * @return mixed
     */
    public static function getQueryModel($model, $request): mixed
    {
        if ($request->input('PName'))
            $model = $model->where('PName', 'like', '%'.$request->input('PName').'%');
        if ($request->input('SName'))
            $model = $model->where('SName', 'like', '%'.$request->input('SName').'%');
        if ($request->input('ToySn'))
            $model = $model->where('ToySn', $request->input('ToySn'));
        if ($request->input('SID'))
            $model = $model->where('SID', $request->input('SID'));
        if ($request->input('skuFlag') != '')
            $model = $model->where('skuFlag', $request->input('skuFlag'));
        if ($request->input('start'))
            $model = $model->whereDate('ITime', '>=', $request->input('start'));;
        if ($request->input('end'))
            $model = $model->whereDate('ITime', '<=', $request->input('end'));;
        return $model;
    }
}
